/*
 * BangoAgent.h
 *
 *  Created on: 5 Feb 2013
 *      Author: sonya
 */

#ifndef BANGOAGENT_H_
#define BANGOAGENT_H_

#include <iostream>
#include <QList>
#include <QThread>
#include <QtConcurrentRun>
#include <QFuture>
#include <bb/cascades/Application>
#include <QMetaEnum>
#include <QMap>

#include "BangoConstants.h"
#include "BangoFieldNames.h"
#include "BangoLogger.h"
#include "BangoStorage.h"
#include "BangoSessionEvents.h"
#include "BangoStatic.h"
#include "BangoNameValuePair.h"
#include "BangoProfile.h"
#include "BangoEvent.h"
#include "BangoPoster.h"
#include "BangoLoggingLevel.h"

class BangoLogger;
class BangoProfile;
class BangoLoggingLevel;
class BangoSessionEvents;

using namespace std;

class BangoAgent : public QObject
{
	Q_OBJECT

private:
	QString _userAgent;
	static QMap <int, QString> _logging_level_events;
	static QVector<int> _active_logging_level;
	static QList<QString> _eventsList;
	static bool _postOnEndSession;
	static bool _postOnEndSessionAsync;
	static BangoLogger _bangoLogger;



	static void startSession(QString applicationKey, QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void endSession(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void PostEventNow();
	static void intSession(QString applicationKey, QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);

	static int getOrdinalIndex(BangoLoggingLevel::ValuesCached bangoLoggingLevel);
	static QVector<int> getOrdinalIndices(int loggingLevel);
	void StartPost(BangoPoster *bangoPoster);
public:
	static BangoProfile Profile();
	static QVector<BangoEvent> Events();
	static void UserAgent(QString userAgent);

	BangoAgent();
	~BangoAgent();

	static bool EventNameAllowed(QString eventName);
	static void setLoggingLevelEvents(BangoLoggingLevel::ValuesCached loggingLevel, QList<QString> eventsList);
	static QMap<int, QString> getLoggingLevelEvents() { return _logging_level_events;}
	static QVector<int> getActiveLoggingLevel(){return _active_logging_level;}
	static void setLoggingLevel(BangoLoggingLevel::ValuesCached loggingLevel);
	static void setLoggingLevel(int loggingLevel);
	static void setLogEnabled(bool logEvents);
	static bool getLogEnabled();
	static void setPersistDatabaseConnection(bool persistDatabaseConnection);
	static bool getPersistDatabaseConnection();
	static void setContinueSessionSeconds(int continueSessionSeconds);
	static int getContinueSessionSeconds();
	static void setUseOfflineStorage(bool useOfflineStorage);
	static bool getUseOfflineStorage();
	static void setApplicationVersion(QString applicationVersion);
	static QString getApplicationVersion();
	static void setUserId(QString userId);
	static QString getUserId();
	static QString getPostURL();
	static void setPostURL(QString postURL);
	static void setApplicationType(QString applicationType);
	static QString getApplicationType();
	static void setApplicationChannel(QString applicationChannel);
	static QString getApplicationChannel();
	static void setFindLocation(bool findLocation);
	static bool getFindLocation();
	static bool getPostOnEndSession();
	static void setPostOnEndSession(bool postOnEndSession);
	static bool getPostOnEndSessionAsync();
	static void setPostOnEndSessionAsync(bool postOnEndSessionAsync);
	static int getMaximumEventsPerProfile();
	static void setMaximumEventsPerProfile(int maximumEventsPerProfile);
	static bool getPostDelayed();
	static void setPostDelayed(bool postDelayed);
	static void PostEvents();


	static void onStartSession(QString applicationKey, QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onStartSession(QString applicationKey, QMap<QString, QString> eventParameters);
	static void onStartSession(QString applicationKey);

	static void onEndSession(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onEndSession(QMap<QString, QString> eventParameters);
	static void onEndSession();

	static void onEvent(QString eventName, QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onEvent(QString eventName, QString eventValue, QMap<QString, QString> eventParameters);
	static void onEvent(QString eventName, QString eventValue, QString eventDetail);
	static void onEvent(QString eventName, QString eventValue);
	static void onEvent(QString eventName);

	static void onDemandVideoStart(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onDemandVideoStart(QString eventValue, QString eventDetail);
	static void onDemandVideoStart(QString eventValue, QMap<QString, QString> eventParameters);
	static void onDemandVideoStart(QString eventValue);
	static void onDemandVideoStart();

	static void onDemandVideoStop(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onDemandVideoStop(QString eventValue, QString eventDetail);
	static void onDemandVideoStop(QString eventValue, QMap<QString, QString> eventParameters);
	static void onDemandVideoStop(QString eventValue);
	static void onDemandVideoStop();

	static void onLiveVideoStart(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onLiveVideoStart(QString eventValue, QString eventDetail);
	static void onLiveVideoStart(QString eventValue, QMap<QString, QString> eventParameters);
	static void onLiveVideoStart(QString eventValue);
	static void onLiveVideoStart();

	static void onLiveVideoStop(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onLiveVideoStop(QString eventValue, QString eventDetail);
	static void onLiveVideoStop(QString eventValue, QMap<QString, QString> eventParameters);
	static void onLiveVideoStop(QString eventValue);
	static void onLiveVideoStop();

	static void onIdle(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onIdle(QString eventValue, QString eventDetail);
	static void onIdle(QString eventValue, QMap<QString, QString> eventParameters);
	static void onIdle(QString eventValue);
	static void onIdle();

	static void onResume(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onResume(QString eventValue, QString eventDetail);
	static void onResume(QString eventValue, QMap<QString, QString> eventParameters);
	static void onResume(QString eventValue);
	static void onResume();

	static void onSearch(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onSearch(QString eventValue, QString eventDetail);
	static void onSearch(QString eventValue, QMap<QString, QString> eventParameters);
	static void onSearch(QString eventValue);
	static void onSearch();

	static void onPageView(QString eventValue, QString eventDetail, QMap<QString, QString> eventParameters);
	static void onPageView(QString eventValue, QString eventDetail);
	static void onPageView(QString eventValue, QMap<QString, QString> eventParameters);
	static void onPageView(QString eventValue);
	static void onPageView();

	static void onError(QString message, QString errorId, QString errorClass);
	static void onError(QString message, QString errorId, QString errorClass, QMap<QString, QString> errorParameters);


	static QString ViewBatch();
public slots:
	void errorString(QString errorString);




};




#endif /* BANGOAGENT_H_ */
